"""


"""
from rest_framework.generics import ListAPIView, CreateAPIView

from meiduo_admin.my_pagination import MyPageNumberPagination
from users.models import User

from meiduo_admin.serializers import user_serializers


class UserListView(ListAPIView, CreateAPIView):

    pagination_class = MyPageNumberPagination

    def get_queryset(self):
        keyword = self.request.query_params.get("keyword")

        if keyword:
            queryset = User.objects.filter(username__contains=keyword)

        else:
            queryset = User.objects.all()

        return queryset

    def get_serializer_class(self):
        if self.request.method == "GET":
            return user_serializers.UserSerializer

        else:
            return user_serializers.UserAddSerialier

    # def post(self, request):
    #     dict_data = request.data
    #
    #     serializer = UserAddSerialier(data=dict_data)
    #
    #     serializer.is_valid(raise_exception=True)
    #
    #     serializer.save()
    #
    #     return Response(serializer.data, status=status.HTTP_201_CREATED)
